package com.aierjun.notepadjun;
import android.app.ActionBar;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by aierJun on 2016/6/18.
 */
public class HistoryActivity extends HelperActivity {
    private DBhelper dBhelper;
    private ImageView add;
    private EditText text;
    private TextView textView;
    private ImageView mButton;
    private PopupWindow mPopupWindow;
    private TextView new_btn,setting_btn,circle_btn,biaoti;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    private ListView shopListView;

    private static final String KEY_TEXT = "text";
    private static final String KEY_TIME = "time";

    private RelativeLayout timu;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_activity_history);
        findView();
        initView();

        add= (ImageView) findViewById(R.id.add_xinjian);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                View popupView = getLayoutInflater().inflate(R.layout.add_activity, null);

                mPopupWindow = new PopupWindow(popupView, ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
                mPopupWindow.setTouchable(true);
                mPopupWindow.setOutsideTouchable(true);
                mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),(Bitmap) null));
                /*mPopupWindow.showAtLocation(findViewById(R.id.add_xinjian), Gravity.CENTER_HORIZONTAL,0,0);*/
                mPopupWindow.showAsDropDown(view,-175,-180);

                new_btn= (TextView) popupView.findViewById(R.id.xinjian);
                setting_btn= (TextView) popupView.findViewById(R.id.shezhi);
                circle_btn= (TextView) popupView.findViewById(R.id.quxiao);

                new_btn.setOnClickListener(onClickListener);
                setting_btn.setOnClickListener(onClickListener);
                circle_btn.setOnClickListener(onClickListener);

            }
        });
    }
    protected  void findView(){
        shopListView = (ListView) findViewById(R.id.historylistview);
        biaoti= (TextView) findViewById(R.id.text_title_1);
        TextView wenben= (TextView) findViewById(R.id.text_title_1);
        /*wenben.setOnClickListener(onClickListener2);*/
        /*timu= (RelativeLayout) findViewById(R.id.tiaomu_layout);*/
    }
    protected void initView() {
       /* if (sharedPreferences.getString("name","").length()!=0){*/
            /*getHeaderView().setTitleText(R.string.user_name);*/
        List<Map<String,String>> data = new ArrayList<>();
            sharedPreferences=getSharedPreferences("newName",MODE_PRIVATE);
            editor=sharedPreferences.edit();
            Map<String,String> map = new HashMap<>();
            map.put(KEY_TEXT,sharedPreferences.getString("name",""));
            map.put(KEY_TIME,"2016/7/1 16:00");
            data.add(map);
        SimpleAdapter shopListAdapter = new SimpleAdapter(HistoryActivity.this,data,R.layout.activity_history_notepad,
                new String[]{KEY_TEXT, KEY_TIME},
                new int[]{R.id.text_title_1,R.id.text_time_1});
            shopListView.setAdapter(shopListAdapter);
   /* }
        timu.setVisibility(View.INVISIBLE);*/
    }

    /*protected void init2View() {
            *//*getHeaderView().setTitleText(R.string.user_name);*//*
        List<Map<String,String>> data = new ArrayList<>();
        sharedPreferences=getSharedPreferences("newName",MODE_PRIVATE);
        editor=sharedPreferences.edit();
        Map<String,String> map = new HashMap<>();
        map.put(KEY_TEXT,sharedPreferences.getString("name","默认文本"));
        map.put(KEY_TIME,"2016/7/1 11:31:12");
        data.add(map);
        SimpleAdapter shopListAdapter = new SimpleAdapter(HistoryActivity.this,data,R.layout.activity_history_notepad,
                new String[]{KEY_TEXT, KEY_TIME},
                new int[]{R.id.text_title_1,R.id.text_time_1});
        shopListView.setAdapter(shopListAdapter);
    }*/
    private View.OnClickListener onClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()){
                case R.id.xinjian:
                    startActivity(new Intent(HistoryActivity.this,NewListActivity.class));
                    break;
                case R.id.shezhi:
                    startActivity(new Intent(HistoryActivity.this,SettingActivity.class));
                    break;
                case R.id.quxiao:
                    finish();
            }
        }
    };
    private View.OnClickListener onClickListener2=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(HistoryActivity.this,NewTextActivity.class));
        }
    };
}
